function validate(){

    var depends = function() {
        if( $('#category').val() != ""){
            if( $('#category').val() == 'Molecula')
                return true;
            else
                return false;
        }else
            return false;
    };
    var depends2 = function() {
        if( $('#category').val() != ""){
            if( $('#category').val() == 'Molecula')
                return false;
            else
                return true;
        }else
            return false;
    };

  $("#formEdit")
        .validate(
        {
            rules : {
                'category' : "required" ,
                'cdaMolecula.droga.id' : { required : depends},
                'cdaMolecula.expiration' : { required :  depends},
                'investigator' : { required :  depends},
                'cdamaster.centro.id' :  { required :  depends2},
                'cdamaster.expiration' : { required :  depends2}
            },
            errorElement : "label"

        });

}

function hideField(){

     if( $('#category').val()  == 'Molecula'){
         $(".master").hide();
   }
     if( $('#category').val()  == 'Master'){
        $(".molecula").hide();
     }
     if( $('#category').val()  == ''){
        $(".master").hide();
        $(".molecula").hide();

     }
}

function getOpcionesCDA(category ){

       if(category != ''){

           if(category == 'Molecula'){

               $(".molecula").show();
               $(".master").hide();
           } else{
               $(".master").show();
               $(".molecula").hide();

           }

       }else{
           hideField();
       }
}

function searchInvestigator(name, url, idlavel){

    windowCaller("Select investigator", url, { "nameOrSurname": name });

}


function closeWindows(name, id){

    $.window.closeAll();
    $("#hdhinvestigatorid").val(id);
    $("#investigator").val(name);


}

function calculateExpirationDate(type, date){

    var dt = date.value;
    var newDt;
    var arr = dt.split("/");
    newDt = arr[0] + "/" + arr[1] + "/" + (parseInt(arr[2]) + 10);
    var d = new Date(newDt);
    if( type == "Molecula" ){
        $("#cdaMoleculaexpiration").datepicker( "option", "dateFormat", 'dd/mm/y' );
        $("#cdaMoleculaexpiration").val($.datepicker.formatDate('dd/mm/y', d));
        $("#cdaMoleculaexpiration").datepicker( "option", "dateFormat", 'dd/M/y' );
    }
    else{
        $("#cdamasterexpiration").datepicker( "option", "dateFormat", 'dd/mm/y' );
        $("#cdamasterexpiration").val($.datepicker.formatDate('dd/mm/y', d));
        $("#cdamasterexpiration").datepicker( "option", "dateFormat", 'dd/M/y' );
    }
}